package com.example.lenovo.myapplication;

import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * Created by Lenovo on 2017/12/18.
 */

public class ChartFragment extends ListFragment {

    private String[] chart_item={"Apple","Apple","Apple","Apple","Apple","Apple","Apple",
            "Apple","Apple","Apple","Apple"};

    private TextView text;

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState){
        View view=inflater.inflate(R.layout.chartfrag_layout,container,false);
        setListAdapter(new ChartAdapter());
        return view;
    }

    private class ChartAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return chart_item.length;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view;
            if(convertView == null){
                view = View.inflate(getActivity(),R.layout.chartitem_layout,null);
            }else{
                view = convertView;
            }
            text = (TextView) view.findViewById(R.id.chart_item);
            text.setText(chart_item[position]);

            return view;

        }
    }
}

